package ch.electronet.wjw.web.actions.ajax.tree;

import java.io.File;

import net.sf.json.JsonConfig;
import ch.electronet.wjw.model.Preferences;

public class GetAlbumsAction extends GetNodesAction {

	private static final long serialVersionUID = 1L;

	private Preferences preferences;

	public void setPreferences(Preferences preferences) {
		this.preferences = preferences;
	}

	@Override
	protected Object doJson(JsonConfig config) {
		config.registerJsonBeanProcessor(FileEntry.class, nodeProcessor);
		String nodeId = getNodeId();
		if (nodeId == null)
			nodeId = new File(preferences.getPicturesRealPath()).getAbsolutePath();
		FileEntry dir = FileEntry.getById(nodeId);
		if (dir != null)
			return dir.getChildren();
		else
			return null;
	}
}
